package com.isscollage.service.impl;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.isscollage.dao.UserDao;
import com.isscollage.entity.Concat;
import com.isscollage.entity.Passenger;
import com.isscollage.entity.Users;
import com.isscollage.search.PassengerSearch;
import com.isscollage.service.UserService;
import com.isscollage.utils.UUIDUtils;

@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserDao userDao;
	@Autowired
	private HttpSession session;
	@Override
	public boolean checkCardNo(String cardNo) {
		// TODO Auto-generated method stub
		Concat concat = userDao.checkCardNo(cardNo);
		if(concat!= null) {
			return true;
		}
		return false;
	}
	@Override
	public Concat searchConcatByCardNo(String cardNo) {
		// TODO Auto-generated method stub
		return  userDao.checkCardNo(cardNo);
	}
	@Override
	public List<Passenger> searchByCon(PassengerSearch search) {
		// TODO Auto-generated method stub
		return userDao.searchByCon(search);
	}
	
	@Override
	public Passenger getPassengerById(Integer passengerId) {
		// TODO Auto-generated method stub
		Passenger passenger = null; 
		if(passengerId!=null){
			passenger = userDao.getPassengerById(passengerId);
		}
		return passenger;
	}
	@Override
	public boolean update(Passenger passenger) {
		// TODO Auto-generated method stub
		boolean flag=false;
		if(passenger!=null && passenger.getPassengerId()!=null){
			flag=userDao.update(passenger);
		}
		return flag;
	}
	@Override
	public boolean insert(Passenger passenger) {
		// TODO Auto-generated method stub
		if(passenger.getPassengerId()!=null){
			passenger.setPassengerId(null);
		}
		passenger.setCreateTime(new Date());
		Users user=(Users) session.getAttribute("user");
		passenger.setCreateId(user.getUserId());	
		passenger.setFlag(0);
		boolean flag = userDao.insert(passenger);
		return flag;
	}
	@Override
	public boolean deleteAll(Integer[] ids) {
		// TODO Auto-generated method stub
		boolean flag=false;
		if(ids!=null && ids.length>0){
			flag=userDao.deleteAll(ids);
		}
		return flag;
	}
	@Override
	public List<Passenger> searchAllPassengers(String userId) {
		// TODO Auto-generated method stub
		return userDao.searchAllPassengers(userId);
	}
	@Override
	public Users getUserByUserId(String userId) {
		// TODO Auto-generated method stub
		if(userId!=null && !"".equals(userId)){
			Users newUser=userDao.getUserByUserId(userId);
			return newUser;
		}
		return null;
	}
	@Override
	public boolean updateUser(Users user) {
		// TODO Auto-generated method stub
		boolean flag=false;
		if(user!=null && !"".equals(user.getUserId())){
			flag=userDao.updateUser(user);
		}
		return flag;
	}

	
}
